package org.example.demo1startjava17.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

/**
 *
 */
@RestController
public class TestController extends ContextPathBaseController {

    @RequestMapping("/test")
    public String test() {
        return "Hello World!";
    }

    @RequestMapping("/test/111")
    public String test222() {
        return "Hello World!222";
    }

    @RequestMapping("/1/test/111")
    public String test2222() {
        return "Hello World!2222";
    }

    @RequestMapping("/robotTest")
    public void robotTest() throws AWTException, InterruptedException {
        Robot robot = new Robot();


//        Thread.sleep(3000);

        // 移动鼠标到(500, 500)
//        robot.mouseMove(500, 500);
        robot.delay(3000); // 等待1秒

        // 鼠标左键点击
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.delay(3000);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
        robot.mouseWheel(-3);
        robot.mouseWheel(3);
        robot.delay(1000);

        // 按下并释放"Hello"键入
        String text = "Hello";
        for (char c : text.toCharArray()) {
            int keyCode = KeyEvent.getExtendedKeyCodeForChar(c);
            if (KeyEvent.CHAR_UNDEFINED == keyCode) {
                throw new RuntimeException("Key code not found for character: " + c);
            }
            robot.keyPress(keyCode);
            robot.keyRelease(keyCode);
            robot.delay(100); // 每个字符之间延迟100毫秒
        }

    }

}
